<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql"%>

<%@page language="java"
	contentType="text/html" 
	pageEncoding="UTF-8"
	import="com.example.validate.UserBean"	
%>

<% 
	UserBean currentUser = (UserBean)session.getAttribute("magicMike");
	String userName = "none";
%>
  	<sql:query var="users" dataSource="jdbc/lut2">
    SELECT name FROM users
	</sql:query>  

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <link rel="stylesheet" type="text/css" href="lutstyle.css">
        <title>LUTAdmin</title>
        <style>.error { color: blue; }</style>
    </head>
    
    <body>
     <%
     	if(currentUser == null){
     		response.sendRedirect("/LUT_2.0/index.jsp");
     	}else {
     	
     %> 
     
     <h1> Velkommen</h1>

     <%
     	userName = currentUser.getUsername();
		out.print("Welcome "+userName);
		out.print("<form action=\"logout.jsp\"><button type=\"submit\">Log out</button></form>");
     	}
     %> 
     
     <form action="AdminManagementServlet" method="post">
     	<table>
     		<tr>
     			<td colspan="2">Add a school to the database</td>
     		</tr>
     		<tr>
     			<td> Full name </td>
     			<td> <input type="text" name="fullName"/> </td>
     		</tr>
     		<tr>
     			<td> Short name</td>
     			<td> <input type="text" name="shortName"/> </td>
     		</tr>
     		<tr>
     			<td> Place </td>
     			<td> <input type="text" name="place"/> </td>
     		</tr>
     		<tr>
     			<td> Zip code </td>
     			<td> <input type="text" name="zip"/> </td>
     		</tr>
     		<tr>
     			<td> Country (short name) </td>
     			<td> <input type="text" name="country"/> </td>
     		</tr>
     		<tr>
     			<td> <input type="submit" value="Add school" name="schoolButton"/></td>
     		</tr>
     		<tr>
     			<td colspan="2"> <span class="error"> ${addSchool}</span> </td>
     		</tr>
     		<tr>
     			<td colspan="2"> Add a country to the database </td>
     		</tr>
     		<tr>
     			<td> Short name </td>
     			<td> <input type="text" name="countrySN"/> </td>
     		</tr>
     		<tr>
     			<td> Full name </td>
     			<td> <input type="text" name="countryFN"/> </td>
     		</tr>
     		<tr>
     			<td> <input type="submit" value="Add country" name="countryButton"/></td>
     		</tr>
     		<tr>
     			<td colspan="2"> <span class="error"> ${addCountry}</span> </td>
     		</tr>
     		<tr>
     			<td colspan="2"> Remove a user from the database </td>
     		</tr>
     		<tr>
     			<td> Select a user: </td>
     			<td> 
		     		<select name="user">
			            <c:forEach var="row" items="${users.rowsByIndex}">
			                <c:forEach var="column" items="${row}">
			
			                    <option value="<c:out value="${column}"/>">
			                    	<c:out value="${column}"/>
			                    </option>
			
			                </c:forEach>
			            </c:forEach>
		        	</select>
     			</td>
     		</tr>
     		<tr>
     			<td> <input type="submit" value="Remove user" name="userButton"/></td>
     		</tr>
     		<tr>
     			<td colspan="2"> <span class="error"> ${removeUser}</span> </td>
     		</tr>
     	</table>
     </form> 
    </body>
</html>
